<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //Object.create(对象,配置对象);
        var obj = Object.create({
            name: "张三",
            age: 20
        })


        var obj1 = Object.create(null, {
            name: {
                value: "张三",
                writeable: true,
                enumerable: true,
                configurable: true
            },
            age: {
                value: 20,
                writeable: true,
                enumerable: true,
                configurable: true
            }
        })

        obj1.name = "李四";
        console.log(obj1);

        for (var key in obj1) {
            console.log(key);
        }

        delete obj1.name;
        console.log(obj1);

        //通过存储器来配置对象

        var obj2 = Object.create(null, {

            name: {
                //getter
                get: function () {
                    console.log("调用get函数");
                    return "张三"
                },
                //setter
                set: function (newvalue) {
                    console.log("修改时", newvalue);

                },
                configurable: true,
                enumerable: true
            }
        });
        //获取值,相当于调用get函数
        obj2.name;

        //设置定时器,自动调用
        setTimeout(() => {
            obj2.name = "李四"
        }, 2000);
    </script>
</body>

</html>